Page({
  data: {
    wallet: {
      balance: 288.50
    },
    transactions: [
      {
        id: 1,
        title: '订单支付',
        time: '2023-05-15 10:35',
        amount: '-198.00',
        type: 'expense'
      },
      {
        id: 2,
        title: '订单退款',
        time: '2023-05-10 14:22',
        amount: '+50.00',
        type: 'income'
      },
      {
        id: 3,
        title: '充值',
        time: '2023-05-01 09:15',
        amount: '+300.00',
        type: 'income'
      }
    ],
    withdrawRecords: [
      {
        id: 1,
        bank: '工商银行',
        time: '2023-05-12 16:30',
        amount: '100.00',
        status: 'completed',
        statusText: '已完成'
      }
    ]
  },

  onLoad: function() {
    this.loadWalletInfo();
  },

  loadWalletInfo: function() {
    const app = getApp();
    
    // 获取钱包信息
    app.request({
      url: `${app.globalData.baseUrl}/wallet/`,
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            wallet: res.data
          });
        }
      }
    });
    
    // 获取交易记录
    app.request({
      url: `${app.globalData.baseUrl}/wallet/transactions/`,
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            transactions: res.data
          });
        }
      }
    });
    
    // 获取提现记录
    app.request({
      url: `${app.globalData.baseUrl}/wallet/withdraw/history/`,
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            withdrawRecords: res.data
          });
        }
      }
    });
  },

  goToRecharge: function() {
    wx.navigateTo({
      url: '/pages/customer/recharge'
    });
  },

  goToWithdraw: function() {
    wx.navigateTo({
      url: '/pages/customer/withdraw'
    });
  },

  goToWithdrawHistory: function() {
    wx.navigateTo({
      url: '/pages/customer/withdrawHistory'
    });
  }
})